package com.example.wjl.Admin;
import com.example.wjl.Model.adminModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.jdbc.core.JdbcTemplate;
import com.example.wjl.Model.User;
import com.example.wjl.Repository.UserRepository;
@Controller

public class WebController {
    @Autowired
    private UserRepository dao;
    private JdbcTemplate  jdbcTemplate;
//    private HashMap result;

    @RequestMapping("/index")

    public String backgroud(Model map){
        User user = new User();
        user.setUname("李四");
        user.setPassward("123123");
        final User save = dao.save(user);

        System.out.println("dddddd"+save);
        Map   user1 = new HashMap();
            user1.put("name","王家乐");
            map.addAllAttributes(user1);
        return "admin/hAdmin/index";
    }
    @RequestMapping("/toIndex")
    public String sencondVC(){
        return "admin/hAdmin/blog";
    }
    @RequestMapping("/login")
    public  String loginAction(){
        return "admin/hAdmin/login_v2";
    }
    @RequestMapping("/loginAction")

    public  String loginActionIsIndex(adminModel admin,HttpServletRequest request, Model model){
        HttpSession session = request.getSession();
        session.setAttribute("username",admin.getUsername());
        HashMap result = new HashMap();
        String sql = "select * from adminuser";

        List list = jdbcTemplate.queryForList(sql);
        System.out.println(list.get(0));
        return "admin/hAdmin/index";
    }

}
